package com.mybatisplus.mp.service;

import com.mybatisplus.mp.mapper.UserMapper;
import com.mybatisplus.mp.pojo.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * Spring事务三大接口 PlatformTransactionManager:(平台)事务管理器 模板方法设计模式
 *                  TransactionDefinition:事务定义信息（事务隔离级别、传播行为、超时、只读、回滚规则）
 *                  TransactionStatus：事务运行状态
 */
@Service
@Slf4j
public class UserService2 {
    @Autowired
    private UserMapper userMapper;

//@Transactional
    public void testA() {
        testB();
        testC();
//        throw new  RuntimeException("故意的");

    }
    @Transactional(propagation= Propagation.REQUIRED)
    public void testB() {
        User build1 = User.builder().version(1)
                .name("testB").build();
        userMapper.insert(build1);

    }
    @Transactional(propagation= Propagation.REQUIRED)
    public void testC() {
        User build1 = User.builder().version(1)
                .name("testC").build();
        userMapper.insert(build1);
        throw new RuntimeException("故意的");
    }
}
